/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.srcptit.javatrainning.thupt.b1;

/**
 *
 * @author Autumn
 */
public class bai8 {
    public static int b[],a[];
    public static void main(String args[]){
        a=new int[7];
        b=new int[4];
        b[0]=2;b[1]=3;b[2]=5;b[3]=7;
        lietke(0); 
                                           }
    public static int tich(){
        int s=0;
        for(int i=0;i<7;i++)s=s*10+a[i];
        return s;
                             }
    public static int tongnguyento(){
        int s=tich();
        for(int i=2;i<=Math.sqrt(s);i++)if(s%i==0)return 0;
        return 1;
                                 }
    public static int kiemtradaytang(){
        for(int i=0;i<6;i++)if(a[i]>a[i+1])return 0;
        return 1;
                                       }
    public static void hienthi(){
        if(kiemtradaytang()==1 && tongnguyento()==1){
                              for(int i=0;i<7;i++)System.out.print(a[i]+ " ");
                              System.out.println();
                                                     }
                                 }
    public static void lietke(int n){
        if(n==7)hienthi();
        else for(int i=0;i<4;i++){a[n]=b[i];
                                 lietke(n+1);
                                 }
                                 }
}